/**
 * Created by sun on 2016/9/9.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');
    var datepicker = require('datepicker');
    var toastr = require('toastr');
    app.useModule("ui.table");

    app.controller('client_remindCtrl', ['$scope','$http','$filter',function ($scope, $http,$filter){

        datepicker($scope);
        $scope.mail={};

        $scope.orderParams = {
            url: "/admin/siteMail/getList"
        };

    $scope.openMailModal= function () {
        $scope.mailModal=!$scope.mailModal
    };

    //保存提醒设置
    $scope.savePrompt= function () {
        console.log($scope.mail);
        $http({
            method: 'POST',
            url:"/admin/siteMail/savePrompt",
            data:$scope.mail
        }).success(function (data){
            if(data.result=='success'){
                toastr.success('设置成功');
                $scope.mailModal=!$scope.mailModal
            }else{
                toastr.error('设置失败')
            }
        }).error(function(data){

        });
    };





//全选
    $scope.single=false;
    var flag='';
        var str='';
    $scope.chooesId=[];
    $scope.isAllCheck= function (c,v) {
        $scope.idArry=[];
        flag='a';
        if(c==true){

            $scope.single=true;
            $http({
                method: 'POST',
                url:"/admin/siteMail/getList",
                data:{}
            }).success(function (data){
                console.log(data);
                for(var i=0;i<data.list.length;i++){
                    $scope.idArry.push(data.list[i].id)
                }
                $scope.chooesId=$scope.idArry;
                console.log($scope.chooesId);
            }).error(function(data){

            });

        }else{
            $scope.single=false;
            $scope.idArry=[];
            $scope.chooesId=[];
        }


    };

   //单选或多选
        $scope.isCheck= function (z,x) {//单选或者多选

            if(flag=='a') {//在全选的基础上操作
                str = $scope.chooesId.join(',') + ',';
                console.log(str)
            }
            if (x == true) {//选中
                str = str + z + ',';
                console.log(str)
            } else {

                str = str.replace(z + ',', '');//取消选中
                console.log(str)
            }

            $scope.chooesId=(str.substr(0,str.length-1)).split(',');
            console.log($scope.chooesId)

        };

        //删除
    $scope.delete= function () {
        for(var i=0;i<$scope.chooesId.length;i++){
            if($scope.chooesId[i]!=''){
                $http({
                    method: 'POST',
                    url:"/admin/siteMail/deleteSiteMail",
                    data:{id:$scope.chooesId[i]}
                }).success(function (data){
                    $scope.orderParams.reload();
                }).error(function(data){

                });
            }
        }

    }



    }]);


});